package project

import (
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"google.golang.org/grpc/resolver"
	"log"
	"project-grpc/project"
	"project-grpc/task"

	"project-api/config"
	"project-common/discovery"
	"project-common/logs"
)

var ProjectServiceClient project.ProjectServiceClient //这里也是grpc.pb文件中的client
var TaskServiceClient task.TaskServiceClient

func InitRpcProjectRpc() {
	etcdRegister := discovery.NewResolver(config.C.EtcdConfig.Addrs, logs.LG) //根据etcd地址, 创建一个自定义的注册器, 该注册器实现了grpc.resolver类的所有方法
	resolver.Register(etcdRegister)                                           //

	//这个grpc服务端的地址在哪
	conn, err := grpc.Dial("etcd:///project", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}

	//你只需要提供连接即可, 我能根据LoginServiceClient的定义, 制作出我要的客户端
	ProjectServiceClient = project.NewProjectServiceClient(conn)
	TaskServiceClient = task.NewTaskServiceClient(conn)
}
